package com.example.newstudent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.newstudent.dao.lessonDao;
import com.example.newstudent.entity.lesson;
import com.example.newstudent.service.lessonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class lessonImpl implements lessonService {
    @Autowired
    lessonDao lessonDao;

    @Override
    public List<lesson> selectAll() {
        return lessonDao.selectList(null);
    }

    @Override
    public lesson lessonUpdate(lesson lesson) {
        UpdateWrapper<lesson> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",lesson.getId());
        lessonDao.update(lesson,updateWrapper);
        return lessonDao.selectOne(updateWrapper);

    }

    @Override
    public List<lesson> lessonByStudentId(int id) {
        QueryWrapper<lesson> queryWrapper=  new QueryWrapper<>();
        queryWrapper.eq("studentid",id);
        return lessonDao.selectList(queryWrapper);
    }

    @Override
    public lesson selectByName(String name) {
        QueryWrapper<lesson> lessonQueryWrapper = new QueryWrapper<>();
        lessonQueryWrapper.eq("name",name);
        return lessonDao.selectOne(lessonQueryWrapper);
    }
}
